package com.kylin.core.merchant.query.handler;

import com.kylin.domain.merchant.vo.Merchant;
import com.kylin.merchant.api.dto.resp.MerchantInfoRespDTO;
import org.mapstruct.Mapper;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * j对象转换接口
 * @author Wall.
 * @version v1.0.1
 * @date 2020年01月09日 20:37
 */
@Mapper(componentModel = "spring")
public interface MerchantTranslator {

    MerchantInfoRespDTO toMerchantRespDTO(Merchant merchant);

    default List<MerchantInfoRespDTO> toMerchantRespDTO(List<Merchant> merchants) {
        return Optional.ofNullable(merchants)
                .orElse(Collections.emptyList())
                .stream()
                .map(this::toMerchantRespDTO)
                .collect(Collectors.toList());
    }
}
